IF exists(SELECT * FROM dbo.sysobjects WHERE name='WEB_dossierInstaptoets' AND xtype='P') 
BEGIN
	DROP PROCEDURE WEB_dossierInstaptoets
END
GO

CREATE  procedure WEB_dossierInstaptoets
(@hoofdNr int,@iNr char(7))
as
select @hoofdNr as hoofdNr,0 as volgNr,'<instap>' +
	'<titel>Instaptoets afgenomen op ' + isNull(datum,'') + '</titel>' +
    	case when (schoolTaal is not null) or (intTaal is not null) 
	  then  '<taal><schools>' + isNull(schoolTaal,'') + '</schools>' +
		'<intel>' + isNull(intTaal,'') + '</intel>' +	
		'<totaal>' + isNull(totTaal,'') + '</totaal></taal>'
	  else '' end +
	case when (schoolWisk is not null) or (intWisk is not null) 
 	  then  '<rekenen><schools>' + isNull(schoolWisk,'') + '</schools>' +	
			'<intel>' + isNull(intWisk,'') + '</intel>' +
			'<totaal>' + isNull(totWisk,'') + '</totaal></rekenen>'
	  else '' end +
        case when (schoolTot is not null) or (intTot is not null) 
	  then '<globaal><schools>' + isNull(schoolTot,'') + '</schools>' +	
		'<intel>' + isNull(intTot,'') + '</intel>'	+
		'<totaal>' + isNull(algTot,'') + '</totaal></globaal>'
	  else '' end + 
	'<studiegewoontes>' + isNull(studiegewoontes,'') + '</studiegewoontes>' +	
	'<soms>' + isNull(onzekerheid,'') + '</soms>' +
	'</instap>' as tekst
  from instaptoets where inschrijvingsNr = @iNr